package cn.hu.pet.controller;

import cn.hu.pet.service.IPetOnlineAuditLogService;
import cn.hu.pet.domain.PetOnlineAuditLog;
import cn.hu.pet.query.PetOnlineAuditLogQuery;
import cn.hu.basic.util.AjaxResult;
import cn.hu.basic.util.AjaxResult;
import cn.hu.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/petOnlineAuditLog")
public class PetOnlineAuditLogController {
    @Autowired
    public IPetOnlineAuditLogService petOnlineAuditLogService;


    /**
     * 保存和修改公用的
     * @param petOnlineAuditLog 传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody PetOnlineAuditLog petOnlineAuditLog) {
        if ( petOnlineAuditLog.getId() != null){
            petOnlineAuditLogService.update(petOnlineAuditLog);
        }else{
            petOnlineAuditLogService.add(petOnlineAuditLog);
        }
        return AjaxResult.getInstance();
    }

    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value = "/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        petOnlineAuditLogService.delete(id);
        return AjaxResult.getInstance();
    }

    //获取用户
    @GetMapping("/{id}")
    public PetOnlineAuditLog get(@PathVariable("id") Long id) {
        return petOnlineAuditLogService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<PetOnlineAuditLog> list() {
        return petOnlineAuditLogService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<PetOnlineAuditLog> json(@RequestBody PetOnlineAuditLogQuery query) {
        return petOnlineAuditLogService.listByQuery(query);
    }
}
